<!DOCTYPE html>
<html lang="en">
<title>编辑训练营</title>
<#import "/layout/layout.html" as body/>
<@body.page>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title overflow">
                    <h5 class="pull-left">编辑训练营</h5>
                </div>
                <div class="ibox-content">
                    <form method="post" enctype="multipart/form-data" class="form-horizontal"
                          name="addForm" id="addForm" action="course_camp_save">
                        <input type="hidden" id="id" name="id" value="${course.id}"/>
                        <div class="form-group"><h3 class="col-sm-12 margin-top">预定信息</h3></div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">训练营名称</label>
                            <div class="col-sm-10">
                                <input id="title" name="title" maxlength="50" value="${course.title!}" type="text" class="form-control">
                                <span class="help-block m-b-none text-right"><i class="pull-right">0/50</i></span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">上课教练</label>
                            <div class="col-sm-10">
                                <select class="form-control m-b chosen-select" id="coachId" name="coachId" data-placeholder="请选择上课教练..." tabindex="2">
                                    <#if coachList??>
                                        <#list coachList as coach>
                                            <option value="${coach.id!}">${coach.nickName!}</option>
                                        </#list>
                                    </#if>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">课程费用</label>
                            <div class="col-sm-10">
                                <div class="input-group m-b"><span class="input-group-addon">¥</span>
                                    <input id="primePrice" name="servicePrice.primePrice" value="${course.servicePrice.primePrice!}" type="number" class="form-control" placeholder="请输入课程费用">
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">会员费用</label>
                            <div class="col-sm-10">
                                <div class="input-group m-b"><span class="input-group-addon">¥</span>
                                    <input id="price" name="servicePrice.price" value="${course.servicePrice.price!}" type="number" class="form-control" placeholder="必填">
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">上课门店</label>
                            <div class="col-sm-10">
                                <select id="storeId" name="storeId" data-placeholder="请选择上课门店..." class="form-control m-b chosen-select" style="width:100%;" tabindex="4">
                                    <#if storeList??>
                                        <#list storeList as store>
                                            <option value="${store.id!}">${store.storeName!}</option>
                                        </#list>
                                    </#if>
                                </select>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">上课周数</label>
                            <div class="col-sm-10">
                                <select id="weeks" name="weeks" data-placeholder="请选择上课周数..." class="form-control m-b chosen-select" style="width:100%;" tabindex="4">
                                    <option value="1">1周</option>
                                    <option value="2">2周</option>
                                    <option value="3">3周</option>
                                    <option value="4">4周</option>
                                    <option value="5">5周</option>
                                    <option value="6">6周</option>
                                    <option value="7">7周</option>
                                    <option value="8">8周</option>
                                    <option value="9">9周</option>
                                    <option value="10">10周</option>
                                    <option value="11">11周</option>
                                    <option value="12">12周</option>
                                    <option value="13">13周</option>
                                    <option value="14">14周</option>
                                    <option value="15">15周</option>
                                    <option value="16">16周</option>
                                    <option value="17">17周</option>
                                    <option value="18">18周</option>
                                    <option value="19">19周</option>
                                    <option value="20">20周</option>
                                </select>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">上课节数</label>
                            <div class="col-sm-10">
                                <input id="periods" name="periods" value="${(course.periods)!}" type="number" min="1"  class="form-control">
                            </div>
                        </div>

                        <!--檬营多节上课时间需要保存在此字段中-->
                        <input type="hidden" id="camp_class_time" name="campClassTime" value="${(course.campClassTime)!}" >

                        <div id="class_time">

                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">起止时间</label>
                            <div class="col-sm-10">
                                <input id="startEndTime" name="startEndTime" value="${course.startEndTime!}" type="text" class="form-control">
                            </div>
                        </div>
                        <!--<div class="hr-line-dashed"></div>-->
                        <!--<div class="form-group"><label class="col-sm-2 control-label">开檬时间</label>-->
                            <!--<div class="col-sm-10">-->
                                <!--<div class="input-group date form_datetime" data-date-format="yyyy-mm-dd hh:ii" data-link-field="dtp_input1">-->
                                    <!--<span class="input-group-addon"><span class="fa fa-calendar"></span></span>-->
                                    <!--<input id="startTime" name="startTime"  class="form-control" size="16" type="text" placeholder="请选择开檬时间" readonly>-->
                                <!--</div>-->
                            <!--</div>-->
                        <!--</div>-->
                        <!--<div class="hr-line-dashed"></div>-->
                        <!--<div class="form-group"><label class="col-sm-2 control-label">闭檬时间</label>-->
                            <!--<div class="col-sm-10">-->
                                <!--<div class="input-group date form_datetime" data-date-format="yyyy-mm-dd hh:ii" data-link-field="dtp_input1">-->
                                    <!--<span class="input-group-addon"><span class="fa fa-calendar"></span></span>-->
                                    <!--<input id="endTime" name="endTime" class="form-control" size="16" type="text" placeholder="请选择闭营时间" readonly>-->
                                <!--</div>-->
                            <!--</div>-->
                        <!--</div>-->
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">成营人数</label>
                            <div class="col-sm-10">
                                <input id="minCount" name="minCount" type="number" min="1" value="${course.minCount!}" class="form-control" placeholder="请输入成营人数">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">满营人数</label>
                            <div class="col-sm-10">
                                <input id="maxCount" name="maxCount" type="number" min="1" value="${course.maxCount!}" class="form-control" placeholder="请输入满营人数">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">截止报名时间</label>
                            <div class="col-sm-10">
                                <div class="input-group date form_datetime" data-date-format="yyyy-mm-dd hh:ii" data-link-field="dtp_input1">
                                    <span class="input-group-addon"><span class="fa fa-calendar"></span></span>
                                    <input id="deadline" name="deadline" value="${course.deadline!?string('yyyy-MM-dd HH:mm')}" readonly class="form-control" size="16" type="text">
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">教练有话说</label>
                            <div class="col-sm-10">
                                <input id="coachComment" name="coachComment" value="${course.coachComment!}" maxlength="100" type="text" class="form-control">
                                <span class="help-block m-b-none text-right"><i class="pull-right">0/100</i></span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">标题背景图</label>
                            <div class="col-sm-10">
                                <div id="head_img" style="min-height: 150px;" class="dropzone">
                                    <input type="hidden" id="headImg" name="headImg" value="${course.headImg!}">
                                    <div class="dropzone-previews"></div>
                                </div>
                            </div>
                        </div>
                        <!--<div class="hr-line-dashed"></div>-->
                        <!--<div class="form-group"><label class="col-sm-2 control-label">训练营群二维码</label>-->
                            <!--<div class="col-sm-10">-->
                                <!--<div id="qun_qr_code" style="min-height: 150px;" class="dropzone">-->
                                    <!--<input id="qunQRCodePic" name="qunQRCodePic" type="hidden" value="${course.qunQRCodePic!}">-->
                                    <!--<div class="dropzone-previews"></div>-->
                                <!--</div>-->
                            <!--</div>-->
                        <!--</div>-->
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <h3 class="col-sm-12 margin-top-5">课程信息
                                <small>(选择课程所属类别后，系统会自动拉取对应的标准课程信息，您可根据需要自行调整文字及图片信息)</small>
                            </h3>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">所属类别</label>
                            <div class="col-sm-10">
                                <select id="courseStandardId" name="courseStandardId" class="form-control m-b">
                                    <option value="0">无</option>
                                    <#if courseStandards??>
                                        <#list courseStandards as courseStandard>
                                            <option value="${courseStandard.id!}">${courseStandard.name!}</option>
                                        </#list>
                                    </#if>
                                </select>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">类别介绍文字</label>
                            <div class="col-sm-10">
                                <textarea id="introduce" name="introduce" class="form-control" rows="6" maxlength="600">${course.introduce!}</textarea>
                                <span class="help-block m-b-none">字数不超过600汉字；可分段描述<i id="introduce-l" class="pull-right">0/600</i></span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">适合人群</label>
                            <div class="col-sm-10">
                                <textarea id="crowd" name="crowd" maxlength="600" class="form-control" rows="3">${course.crowd!}</textarea>
                                <span class="help-block m-b-none">字数不超过600汉字；可分段描述<i class="pull-right">0/600</i></span>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">属性标签</label>
                            <input id="courseAttr" name="courseAttr" type="hidden" value="${course.courseAttr!}">
                            <div class="col-sm-10">
                                <div id="magicsuggest"></div>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">视频链接</label>
                            <div class="col-sm-10">
                                <input id="link" name="link" value="${course.link!}" type="text" class="form-control" placeholder="请输入视频链接">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">视频封面图</label>
                            <input type="hidden" id="url" name="url" value="${course.url!}">
                            <div class="col-sm-10">
                                <div id="video_preview" style="min-height: 230px;" class="dropzone">
                                    <div class="dropzone-previews"></div>
                                </div>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group"><label class="col-sm-2 control-label">类别硬照</label>
                            <input type="hidden" id="categoryPic" name="categoryPic" value="${course.categoryPic!}">
                            <div class="col-sm-10">
                                <div id="category_pic" style="min-height: 230px;" class="dropzone">
                                    <div class="dropzone-previews"></div>
                                </div>
                                <div class="m text-left">
                                    <small>大小不能超过1.5M;必须大于两张，且总数为偶数。</small>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="ibox-content overflow">
                    <div class="col-sm-12">
                        <button type="button" onclick="goBackList()" class="btn btn-default pull-left">取消编辑</button>
                        <button type="button" onclick="saveCourse()" class="btn btn-primary pull-right">编辑保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--<link href="${baseUrl}css/plugins/clockpicker/clockpicker.css" rel="stylesheet">-->
<link href="${baseUrl}css/plugins/magicsuggest/magicsuggest-min.css" rel="stylesheet">
<!--upload-->
<script type="text/javascript" src="${baseUrl}js/upload/promise.min.js"></script>
<script type="text/javascript" src="${baseUrl}js/upload/aliyun-oss-sdk.min.js"></script>
<script type="text/javascript" src="${baseUrl}js/upload/webToOss.js"></script>
<script src="${baseUrl}js/plugins/dropzone/dropzone.js"></script>
<script src="${baseUrl}js/plugins/clockpicker/clockpicker.js"></script>

<script>
    var ms = null;//下拉插件
    var dictArr = new Array();
    var dataDictList = ${dataDictList!};
    var headImgPicList = new Array();//标题背景图
//    var qrcodePicList = new Array();//群QRCODE
    var videoLinkPicList = new Array();//视频封面
    var categoryPicList = new Array();//类别硬照
    var courseStandard;
    var myDropzone;
    var myDropzone2;
    var myDropzone3;

    //返回列表
    function goBackList() {
        window.location = "to_course_camp_list";
    }
    //保存方法
    function saveCourse() {
        debugger
        var isCheck = true;
        //校验表单
        if ($("#title").val().length <= 0) {
            swal("错误!", "请先填写训练营名称!", "error");
            isCheck = false;
            return false;
        }
        if ($("#primePrice").val().length <= 0) {
            swal("错误!", "请先输入课程费用!", "error");
            isCheck = false;
            return false;
        }
        if ($("#price").val().length <= 0) {
            swal("错误!", "请先输入课程会员费用!", "error");
            isCheck = false;
            return false;
        }
        if ($("#storeId").val() == null) {
            swal("错误!", "请先选择上课门店!", "error");
            isCheck = false;
            return false;
        }
        if ($("#periods").val().length <= 0) {
            swal("错误!", "请先输入上课节数!", "error");
            isCheck = false;
            return false;
        }

        var $input = $("input[name='cct']");
        var $cct = $("#camp_class_time");

        $input.each(function(i, data){
            console.log("i = " + i + " data = " + data.value);
            if (data.value.trim().length === 0) {
                swal("错误!", "请先确定上课时间!", "error");
                isCheck = false;
                return false;
            } else {
                //保存所有上课时间到 camp_class_time

                if (i === 0) {
                    $cct.val( data.value );
                } else {
                    $cct.val( $cct.val() + "," + data.value )
                }
            }
        });


        if (!isCheck) {
            return false;
        }
        console.info("cct ---> " + $cct.val());

        if ($("#startEndTime").val().length <= 0) {
            swal("错误!", "请先输入起止时间!", "error");
            isCheck = false;
            return false;
        }
//        if ($("#startTime").val().length <= 0) {
//            swal("错误!", "请先选择开檬时间!", "error");
//            isCheck = false;
//            return false;
//        }
//        if ($("#endTime").val().length <= 0) {
//            swal("错误!", "请先选择闭檬时间!", "error");
//            isCheck = false;
//            return false;
//        }
        if ($("#minCount").val().length <= 0) {
            swal("错误!", "请先输入成营人数!", "error");
            isCheck = false;
            return false;
        }
        if ($("#maxCount").val().length <= 0) {
            swal("错误!", "请先输入满营人数!", "error");
            isCheck = false;
            return false;
        }
        if ($("#maxCount").val() > 0 && $("#minCount").val() > 0 && parseInt($("#minCount").val()) > parseInt($("#maxCount").val())) {
            //开营人数不得大于满营人数
            swal("错误!", "成营人数不能大于满营人数!", "error");
            isCheck = false;
            return false;
        }
        if ($("#deadline").val().length <= 0) {
            swal("错误!", "请先选择截止报名时间!", "error");
            isCheck = false;
            return false;
        }
        if ($("#coachComment").val().length <= 0) {
            swal("错误!", "请先输入教练有话说!", "error");
            isCheck = false;
            return false;
        }
        $("#headImg").val(headImgPicList.join(","));
        if ($("#headImg").val().length <= 0) {
            swal("错误!", "请先上传标题背景图!", "error");
            isCheck = false;
            return false;
        } else {
            if ($("#headImg").val().split(",").length != 1) {
                swal("错误!", "请先确定上传1张数量的标题背景图!", "error");
                isCheck = false;
                return false;
            }
        }
//        $("#qunQRCodePic").val(qrcodePicList.join(","));
//        if ($("#qunQRCodePic").val().length <= 0) {
//            swal("错误!", "请先上传教练微信二维码!", "error");
//            isCheck = false;
//            return false;
//        } else {
//            if ($("#qunQRCodePic").val().split(",").length != 1) {
//                swal("错误!", "请先确定上传1张数量的教练微信二维码!", "error");
//                isCheck = false;
//                return false;
//            }
//        }
        if ($("#introduce").val().length <= 0) {
            swal("错误!", "请先输入类别介绍文字!", "error");
            isCheck = false;
            return false;
        }
        if ($("#crowd").val().length <= 0) {
            swal("错误!", "请先输入适合人群!", "error");
            isCheck = false;
            return false;
        }
//            debugger
        $("#courseAttr").val(dictArr.toString());
        if ($("#courseAttr").val() == "") {
            swal("错误!", "请先选择属性标签!", "error");
            isCheck = false;
            return false;
        }

//	        if($('#courseStandardId').val()!=''){
//	            //标准课程为空时不校验视频链接/视频封面图
//	            if($("#link").val().length<=0) {
//	                swal("错误!", "请先输入视频链接!", "error");
//	                isCheck = false;
//	                return false;
//	            }
//	            $("#url").val(videoLinkPicList.join(","));
//	            if($("#url").val().length<=0) {
//	                swal("错误!", "请先上传视频封面图!", "error");
//	                isCheck = false;
//	                return false;
//	            } else {
//	                if ($("#url").val().split(",").length != 1) {
//	                    swal("错误!", "请先确定上传1张数量的视频封面图!", "error");
//	                    isCheck = false;
//	                    return false;
//	                }
//	            }
//	        }

        $("#url").val(videoLinkPicList.join(","));
        if (videoLinkPicList.length > 0 && videoLinkPicList.length != 1) {
            swal("错误!", "请先确定上传1张数量的视频封面图!", "error");
            isCheck = false;
            return false;
        }
        $("#categoryPic").val(categoryPicList.join(","));
        if ($("#categoryPic").val().length <= 0) {
            swal("错误!", "请先上传类别硬照!", "error");
            isCheck = false;
            return false;
//        } else {
//            if ($("#categoryPic").val().split(",").length % 2 != 0) {
//                swal("错误!", "请先上传偶数量的类别硬照!", "error");
//                isCheck = false;
//                return false;
//            }
        }

        if (!isCheck) {
            return false;
        }
        var param = $("#addForm").serialize();
        debugger;
        console.log("info === > " + param);

        $("#saveBtn").attr('disabled', "true");
        $.ajax({
            type: "post",
            url: "course_camp_save",
            data: param,
            success: function (data) {
                if (data == "success") {
                    swal("保存成功!", "页面即将重新加载,请稍后...", "success");
                    window.setTimeout(function () {
                        window.location = "to_course_camp_list";
                    }, 1000);
                } else {
                    swal("保存失败!", data, "error");
                }
            }
        });
    }

    $(document).ready(function () {
        //下拉选择
        if ($('#courseAttr').val().trim().length <= 0) {
            ms = $('#magicsuggest').magicSuggest({
                data: dataDictList,
                placeholder: '请输入搜索或选择',
                required: true,
                expandOnFocus: true,
                strictSuggest: true,
                displayField: 'dictName',
                valueField: 'dictName'
            });
        } else {
            ms = $('#magicsuggest').magicSuggest({
                data: dataDictList,
                placeholder: '请输入搜索或选择',
                required: true,
                expandOnFocus: true,
                strictSuggest: true,
                displayField: 'dictName',
                valueField: 'dictName',
                value: $('#courseAttr').val().split('#')
            });
            dictArr = ms.getValue();
        }

        $(ms).on('selectionchange', function () {
            console.log('DATA---->>' + JSON.stringify(this.getValue()));
            dictArr = this.getValue();
        });
        var courseJson = ${courseJson!};
        if (courseJson) {
            if (courseJson.id) {
                $("#id").val(courseJson.id);
            }
            if (courseJson.coachId) {
                $("#coachId").val(courseJson.coachId);
            }
            if (courseJson.storeId) {
                $("#storeId").val(courseJson.storeId);
            }
            if (courseJson.weeks) {
                $("#weeks").val(courseJson.weeks);
            }
            if (courseJson.courseStandardId) {
                $("#courseStandardId").val(courseJson.courseStandardId);
            }
            if (courseJson.standCourse) {
                courseAttr = courseJson.standCourse;
            }

        }
        //标题背景图
        Dropzone.autoDiscover = false;
        myDropzone = new Dropzone("#head_img", {
            url: "upload_pic",
            uploadMultiple: false,
            addRemoveLinks: true,
            dictDefaultMessage: "将文件拖到此处上传",
            dictFileTooBig: "文件过大",
            dictCancelUpload: "取消上传",
            dictRemoveFile: "移除文件",
            dictMaxFilesExceeded: "超过上传文件数量限制",
            maxFiles: 1,
            maxFilesize: 10.5,
            acceptedFiles: ".jpg,.jpeg,.png",
            method: 'post',
            filesizeBase: 1024,

            init: function () {
                var url = $("#headImg").val();
                if (!url || url.length <= 0) {
                    url = "";
                } else {
                    var larr = url.split(",");
                    if (larr.length > 0) {
                        for (var i = 0; i < larr.length; i++) {
                            headImgPicList.push(larr[i]);
                        }
                    }
                }
                this.emit("initimage", url);
                this.on("error", function (file, response, XMLHttpRequest) {
                    if(response == '超过上传文件数量限制'){
                        swal("图片上传异常!", '超过上传文件数量限制', "error");
                    } else {
                        swal("图片上传异常!", "图片服务器出错,即将清除无效图片,请稍后重新上传...", "error");
                        window.setTimeout(function () {
                            $('#head_img .dz-image-preview.dz-error').remove()
                        }, 1000);
                    }
                });
                this.on("success", function (file, response, e) {
                    if (response.error) {
                        $(file.previewTemplate).children('.dz-error-mark').css('opacity', '1')
                    } else {
                        headImgPicList.push(response.url);
                    }
                });
                this.on("sending", function (file, xhr, formData) {
                    formData.append("filesize", file.size);
                });
                this.on("removedfile", function (file) {
                    var responseJson = null;
                    if (file && file.xhr && file.xhr.responseText) {
                        responseJson = $.parseJSON(file.xhr.responseText);
                    }
                    if (responseJson) {
                        $.each(headImgPicList, function (i, data) {
                            if (headImgPicList[i].indexOf(responseJson.url) > -1) {
                                headImgPicList.splice(i, 1);
                            }
                        });
                    }
                    if (file.name.length > 0) {
                        for (var i = 0; i < headImgPicList.length; i++) {
                            if (headImgPicList[i].indexOf(file.name) > -1) {
                                headImgPicList.splice(i, 1);
                                break
                            }
                        }
                        console.log("文件 " + file.name + " 被移除");
                    }
                });
            }
        });

        //视频封面图
        myDropzone2 = new Dropzone("#video_preview", {
            url: "upload_pic",
            uploadMultiple: false,
            addRemoveLinks: true,
            dictDefaultMessage: "将文件拖到此处上传",
            dictFileTooBig: "文件过大",
            dictCancelUpload: "取消上传",
            dictRemoveFile: "移除文件",
            dictMaxFilesExceeded: "超过上传文件数量限制",
            maxFiles: 1,
            maxFilesize: 10.5,
            acceptedFiles: ".jpg,.jpeg,.png",
            method: 'post',
            filesizeBase: 1024,

            init: function () {
                var url = $("#url").val();
                if (!url || url.length <= 0) {
                    url = "";
                } else {
                    var larr = url.split(",");
                    if (larr.length > 0) {
                        for (var i = 0; i < larr.length; i++) {
                            videoLinkPicList.push(larr[i]);
                        }
                    }
                }
                this.emit("initimage", url);
                this.on("error", function (file, response, XMLHttpRequest) {
                    debugger
                    swal("图片上传异常!", "图片服务器出错,即将清除无效图片,请稍后重新上传...", "error");
                    window.setTimeout(function () {
                        $('#video_preview .dz-image-preview.dz-error').remove()
                    }, 1000);
                });
                this.on("success", function (file, response, e) {
                    if (response.error) {
                        $(file.previewTemplate).children('.dz-error-mark').css('opacity', '1')
                    } else {
                        videoLinkPicList.push(response.url);
                    }
                });
                this.on("sending", function (file, xhr, formData) {
                    formData.append("filesize", file.size);
                });
                this.on("removedfile", function (file) {
                    var responseJson = null;
                    if (file && file.xhr && file.xhr.responseText) {
                        responseJson = $.parseJSON(file.xhr.responseText);
                    }
                    if (responseJson) {
                        $.each(videoLinkPicList, function (i, data) {
                            if (videoLinkPicList[i].indexOf(responseJson.url) > -1) {
                                videoLinkPicList.splice(i, 1);
                            }
                        });
                    }
                    if (file.name.length > 0) {
                        for (var i = 0; i < videoLinkPicList.length; i++) {
                            if (videoLinkPicList[i].indexOf(file.name) > -1) {
                                videoLinkPicList.splice(i, 1);
                                break
                            }
                        }
                        console.log("文件 " + file.name + " 被移除");
                    }
                });
            }
        });

        //类别硬照
        myDropzone3 = new Dropzone("#category_pic", {
            url: "upload_pic",
            uploadMultiple: false,
            addRemoveLinks: true,
            dictDefaultMessage: "将文件拖到此处上传",
            dictFileTooBig: "文件过大",
            dictCancelUpload: "取消上传",
            dictRemoveFile: "移除文件",
            maxFilesize: 10.5,
            acceptedFiles: ".jpg,.jpeg,.png",
            method: 'post',
            filesizeBase: 1024,

            init: function () {
                var url = $("#categoryPic").val();
                if (!url || url.length <= 0) {
                    url = "";
                } else {
                    var larr = url.split(",");
                    if (larr.length > 0) {
                        for (var i = 0; i < larr.length; i++) {
                            categoryPicList.push(larr[i]);
                        }
                    }
                }
                this.emit("initimage", url);
                this.on("error", function (file, response, XMLHttpRequest) {
                    debugger
                    swal("图片上传异常!", "图片服务器出错,即将清除无效图片,请稍后重新上传...", "error");
                    window.setTimeout(function () {
                        $('#category_pic .dz-image-preview.dz-error').remove()
                    }, 1000);
                });
                this.on("success", function (file, response, e) {
                    if (response.error) {
                        $(file.previewTemplate).children('.dz-error-mark').css('opacity', '1')
                    } else {
                        categoryPicList.push(response.url);
                    }
                });
                this.on("sending", function (file, xhr, formData) {
                    formData.append("filesize", file.size);
                });
                this.on("removedfile", function (file) {
                    var responseJson = null;
                    if (file && file.xhr && file.xhr.responseText) {
                        responseJson = $.parseJSON(file.xhr.responseText);
                    }
                    if (responseJson) {
                        $.each(categoryPicList, function (i, data) {
                            if (categoryPicList[i].indexOf(responseJson.url) > -1) {
                                categoryPicList.splice(i, 1);
                            }
                        });
                    }
                    if (file.name.length > 0) {
                        for (var i = 0; i < categoryPicList.length; i++) {
                            if (categoryPicList[i].indexOf(file.name) > -1) {
                                categoryPicList.splice(i, 1);
                            }
                            console.log("文件 " + file.name + " 被移除");
                        }
                    }
                });
            }
        });
        $('#deadline').datetimepicker({
            language: 'zh-CN',
            weekStart: 1,
            todayBtn: 1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            showMeridian: 0
        });
//        $('input[name="startTime"]').daterangepicker({
 //           startDate: "",
 //           endDate: "}",
//          minDate: "",//'01/01/2016',    //最小时间new Date(),//
//            minDate: new Date(),//'01/01/2016',    //最小时间new Date(),//
//            maxDate: 0,//moment(), //最大时间
//            dateLimit: {days: 60}, //起止时间的最大间隔
//            showWeekNumbers: false, //是否显示第几周
//            timePicker: true, //是否显示小时和分钟
//            timePicker12Hour: false, //是否使用12小时制来显示时间
//            timePickerIncrement:10,
//            opens: 'right', //日期选择框的弹出位置
//            buttonClasses: ['btn btn-default'],
//            applyClass: 'btn-small btn-primary blue',
//            cancelClass: 'btn-small',
//            format: 'YYYY-MM-DD HH:mm', //控件中from和to 显示的日期格式 YYYY-MM-DD HH:mm:ss
//            separator: '~',
//            locale: {
//                applyLabel: '确定',
//                cancelLabel: '取消',
//                fromLabel: '开营时间',
//                toLabel: '闭营时间',
//                customRangeLabel: '自定义',
//                daysOfWeek: ['日', '一', '二', '三', '四', '五', '六'],
//                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月',
//                    '七月', '八月', '九月', '十月', '十一月', '十二月'],
//                firstDay: 1
//            }
//        }, function (start, end, label) {//格式化日期显示框

//          此方法如果在当前值和确定按钮按下值相同 将导致 开始结束时间放进一个input
//          $('.date-rangepicker span').html(start.format('YYYY-MM-DD HH:mm') + ' - ' + end.format('YYYY-MM-DD HH:mm'));
//          $('#startTime').val(start.format('YYYY-MM-DD'));
//          $('#endTime').val(end.format('YYYY-MM-DD'));
//        });

        $('#startTime').on('apply.daterangepicker', function (ev, picker) {
            //解决input中开始结束时间被不正确放到了一个input中的问题
            var timeArr = ev.currentTarget.value.split("~");
            debugger
            $('#startTime').val(timeArr[0].substring(0, 16));
            $('#endTime').val(timeArr[1].substring(0, 16));
        });


        //loadStandard($("#courseStandardId").children('option:selected').val(), false);

        bindEventer('title', 50);
        bindEventer('coachComment', 100);
        bindEventer('introduce', 600);
        bindEventer('crowd', 600);

        $("#title, #coachComment, #introduce, #crowd").trigger("keyup");

        $("#storeId").trigger("change");


        var temp =
            '<div class="form-group"><label class="col-sm-2 control-label">上课时间</label>\n' +
            '<div class="col-sm-10\">\n' +
            '<div class="input-group date form_datetime" data-date-format="yyyy-mm-dd hh:ii" >\n' +
            '<span class="input-group-addon"><span class="fa fa-calendar"></span></span>\n' +
            '<input id="classTime" name="campTime" class="form-control" size="16" type="text" placeholder="请选择上课时间" readonly>\n' +
            '</div>\n' +
            '</div>\n' +
            '</div>'
        ;

        var periods = $("#periods");
        //上课节数监听器
        periods.keyup(function(event) {
            $("#class_time").html("");
            var $campClassTime = $("#camp_class_time");

            for (var i = 0; i < this.value; i++) {
                console.info("i value " + i);
                var tNum = i + 1;

                $("#class_time").append(temp.replace(/上课时间/, "上课时间" + tNum).replace(/classTime/, "classTime" + tNum).replace(/campTime/, "cct"));

                $('input[name="cct"]').datetimepicker({
                    language: 'zh-CN',
                    weekStart: 1,
                    todayBtn: 1,
                    autoclose: 1,
                    todayHighlight: 1,
                    startView: 2,
                    forceParse: 0,
                    showMeridian: 0
                });
debugger;
                var tempT = $campClassTime.val().split(",");

                $("#classTime"+ tNum).val(tempT[i]).datetimepicker('update');
            }
        });

        periods.trigger("keyup");

    });


    //动态改变基础课程值
    $("#courseStandardId").change(function () {
        var id = $(this).children('option:selected').val();
        debugger
        if (id == '') {
            //为空清空标准课程
            $('#url').val('');
            $('#introduce').val('');
            $('#crowd').val('');
            $('#link').val('');
            ms.clear();
            ms.collapse();
            $('#video_preview .dz-image-preview').remove();
            videoLinkPicList = new Array;
        } else {
            loadStandard(id, false);
        }

    })
    /**
     * 读取标准课程数据
     * @param id
     * @param isFirst 是否首次调用 ture 是 /false 不是
     */
    function loadStandard(id, isFirst) {

        if (id == '0') {

        } else {
            $.ajax({
                type: "post",
                url: "course_standard",
                data: {"id": id},
                success: function (data) {
                    courseStandard = $.parseJSON(data);
                    if (courseStandard) {
                        debugger
                        if (!isFirst) {//非第一次进入调用才更新标准课程关联字段值

                            $("#introduce").val(courseStandard.introduce).trigger("keyup");
                            $("#crowd").val(courseStandard.crowd).trigger("keyup");
                            $("#link").val(courseStandard.link);
                            $("#video_preview .dz-image-preview, #category_pic .dz-image-preview").remove();
                            videoLinkPicList = new Array;
                            if (courseStandard.url && courseStandard.url.length > 0) {
                                videoLinkPicList.push(courseStandard.url);
                                var mockFile = {name: courseStandard.url, accepted: true};
                                myDropzone2.emit("addedfile", mockFile);
                                myDropzone2.emit("thumbnail", mockFile, courseStandard.url);
                                myDropzone2.emit("complete", mockFile);
                            }
                            categoryPicList = new Array();
                            if (courseStandard.categoryPic && courseStandard.categoryPic.length > 0) {
                                var urlArr = courseStandard.categoryPic.split(",");
                                for (var i = 0; i < urlArr.length; i++) {
                                    categoryPicList.push(urlArr[i]);
                                    var mockFile = {name: urlArr[i], accepted: true};
                                    myDropzone3.emit("addedfile", mockFile);
                                    myDropzone3.emit("thumbnail", mockFile, urlArr[i]);
                                    myDropzone3.emit("complete", mockFile);
                                }
                            }
                            if (courseStandard.courseAttr && courseStandard.courseAttr.length > 0) {
                                var cd = courseStandard.courseAttr.split("#");
                                ms.clear();
                                ms.setValue(cd);
                                ms.collapse();
                            } else {
                                ms.clear();
                                ms.collapse();
                            }
                        }
                    }
                }
            });
        }
    }

</script>

</@body.page>
</html>